package com.sduept.nwld.dataserver.manager.protection;

import com.sduept.core.dao.SuperDAO;
import com.sduept.nwld.dataserver.model.daily.ProtectDefect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ProtectDefectManager {
	@Autowired
	SuperDAO dao;
	
	public List<ProtectDefect> getProtectDefect(Date start,Date end){
		return dao.findByCondition(ProtectDefect.class, " protectQuitTime between ? and ? order by protectQuitTime desc", start,end);
	}
	
	public List<ProtectDefect> getProtectDefect(Date start,Date end,String stationId){
		return dao.findByCondition(ProtectDefect.class, " protectQuitTime between ? and ? and substationId = ? order by protectQuitTime desc", start,end,stationId);
	}
	

	/**
	 * 单条删除
	 */
	public void delProtectDefect(ProtectDefect selectProtectDefect) {
		if (selectProtectDefect != null) {
			try {
				dao.delete(selectProtectDefect.getId(), ProtectDefect.class);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	/**
	 * 单条编辑
	 */
	public void editUpdate( ProtectDefect selected){
		if(selected  != null){
			dao.update(selected, ProtectDefect.class);
		} 
	}
	

	/**
	 * 数据更新
	 */
	public void updateProtectDefect(ProtectDefect selectProtectDefect) {
		if (selectProtectDefect != null) {
			try {
				dao.update(selectProtectDefect, ProtectDefect.class); // update新的数据到这条Overhaulmag
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	/**
	 * 新增数据
	 * 
	 * @return
	 */
	public ProtectDefect creatProtectDefect(ProtectDefect created) {
		if (created != null) {
			try {
				created = dao.create(created, ProtectDefect.class);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return created;
	}
}
